package com.anlen.experimentfour;

import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	EditText username;
	EditText password;
	Button login;
	CheckBox check;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		username = (EditText) findViewById(R.id.username);
		password = (EditText) findViewById(R.id.password);
		check = (CheckBox) findViewById(R.id.checkBox1);
		
		Map<String,String> map=FileService.getinfo(this);
		
	/*	
		SharedPreferences sp=getSharedPreferences("config", Context.MODE_PRIVATE);
		username.setText(sp.getString("username", ""));
		password.setText(sp.getString("password", ""));
	*/
		if(map!=null){
			username.setText(map.get("name"));
			password.setText(map.get("password"));
		}
	}
	
	public void login(View view){
		String names;
		String passwords;
		names = username.getText().toString().trim();
		passwords = password.getText().toString().trim();
		if(TextUtils.isEmpty(names)||TextUtils.isEmpty(passwords)){
			Toast.makeText(this, "账户或者密码不能为空", Toast.LENGTH_SHORT);
		}
			
		if(check.isChecked()){
			/*	
			SharePreferenceService.saveInfo(this, names, passwords);
			 */
			FileService fileService=new FileService();
			fileService.saveInfo(this, names, passwords);
			
			Toast.makeText(this, "保存信息到本地文件中，下次登录就会显示上次登录的信息", Toast.LENGTH_SHORT).show();
		}
	}
	
}
